package JZ54_字符流中第一个不重复的字符;

import java.util.LinkedList;
import java.util.Queue;

public class Solution {
    int[] charCnt = new int[128];
    Queue<Character> queue = new LinkedList<>();
    //Insert one char from stringstream
    public void Insert(char ch)
    {
        if (charCnt[ch]++ == 0){
            queue.add(ch);
        }
    }
    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    {
        Character character = null;
        char c = 0;
        while ((character = queue.peek()) != null){
            c = character.charValue();
            if (charCnt[c] == 1){
                return c;
            }else {
                queue.remove();
            }
        }
        return '#';
    }
}